from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-12 14:12:42.101721
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 12, Aug, 2021
Time: 14:12:46
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.5969
Nobs: 381.000 HQIC: -46.1587
Log likelihood: 4088.09 FPE: 6.20992e-21
AIC: -46.5282 Det(Omega_mle): 4.91835e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.461786 0.097700 4.727 0.000
L1.Burgenland 0.103076 0.050431 2.044 0.041
L1.Kärnten -0.116081 0.024458 -4.746 0.000
L1.Niederösterreich 0.163397 0.106920 1.528 0.126
L1.Oberösterreich 0.110185 0.105715 1.042 0.297
L1.Salzburg 0.296190 0.051853 5.712 0.000
L1.Steiermark 0.015167 0.068731 0.221 0.825
L1.Tirol 0.124788 0.054284 2.299 0.022
L1.Vorarlberg -0.113851 0.048886 -2.329 0.020
L1.Wien -0.038800 0.094972 -0.409 0.683
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const -0.013857 0.231209 -0.060 0.952
L1.Burgenland -0.041479 0.119347 -0.348 0.728
L1.Kärnten 0.034699 0.057881 0.599 0.549
L1.Niederösterreich -0.247499 0.253029 -0.978 0.328
L1.Oberösterreich 0.554568 0.250177 2.217 0.027
L1.Salzburg 0.310950 0.122712 2.534 0.011
L1.Steiermark 0.114480 0.162654 0.704 0.482
L1.Tirol 0.300534 0.128465 2.339 0.019
L1.Vorarlberg -0.012979 0.115691 -0.112 0.911
L1.Wien 0.013354 0.224753 0.059 0.953
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.258508 0.050083 5.162 0.000
L1.Burgenland 0.094963 0.025852 3.673 0.000
L1.Kärnten -0.003276 0.012538 -0.261 0.794
L1.Niederösterreich 0.226590 0.054810 4.134 0.000
L1.Oberösterreich 0.152770 0.054192 2.819 0.005
L1.Salzburg 0.037531 0.026581 1.412 0.158
L1.Steiermark 0.013121 0.035233 0.372 0.710
L1.Tirol 0.073921 0.027827 2.656 0.008
L1.Vorarlberg 0.058200 0.025060 2.322 0.020
L1.Wien 0.088435 0.048685 1.816 0.069
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195424 0.048933 3.994 0.000
L1.Burgenland 0.040895 0.025258 1.619 0.105
L1.Kärnten -0.006683 0.012250 -0.546 0.585
L1.Niederösterreich 0.123143 0.053551 2.300 0.021
L1.Oberösterreich 0.311243 0.052947 5.878 0.000
L1.Salzburg 0.101704 0.025971 3.916 0.000
L1.Steiermark 0.139044 0.034424 4.039 0.000
L1.Tirol 0.077268 0.027188 2.842 0.004
L1.Vorarlberg 0.055559 0.024485 2.269 0.023
L1.Wien -0.038601 0.047566 -0.812 0.417
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.201806 0.097542 2.069 0.039
L1.Burgenland -0.058700 0.050350 -1.166 0.244
L1.Kärnten -0.037582 0.024418 -1.539 0.124
L1.Niederösterreich 0.081863 0.106747 0.767 0.443
L1.Oberösterreich 0.196177 0.105544 1.859 0.063
L1.Salzburg 0.265863 0.051770 5.136 0.000
L1.Steiermark 0.076277 0.068620 1.112 0.266
L1.Tirol 0.124351 0.054197 2.294 0.022
L1.Vorarlberg 0.119296 0.048808 2.444 0.015
L1.Wien 0.034910 0.094818 0.368 0.713
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.035833 0.076439 0.469 0.639
L1.Burgenland 0.026997 0.039457 0.684 0.494
L1.Kärnten 0.050478 0.019136 2.638 0.008
L1.Niederösterreich 0.191928 0.083653 2.294 0.022
L1.Oberösterreich 0.343758 0.082710 4.156 0.000
L1.Salzburg 0.048486 0.040569 1.195 0.232
L1.Steiermark -0.001175 0.053774 -0.022 0.983
L1.Tirol 0.116033 0.042471 2.732 0.006
L1.Vorarlberg 0.062329 0.038248 1.630 0.103
L1.Wien 0.126549 0.074305 1.703 0.089
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166907 0.092978 1.795 0.073
L1.Burgenland 0.023992 0.047994 0.500 0.617
L1.Kärnten -0.061376 0.023276 -2.637 0.008
L1.Niederösterreich -0.115175 0.101752 -1.132 0.258
L1.Oberösterreich 0.192650 0.100605 1.915 0.056
L1.Salzburg 0.031373 0.049347 0.636 0.525
L1.Steiermark 0.304828 0.065409 4.660 0.000
L1.Tirol 0.492820 0.051661 9.540 0.000
L1.Vorarlberg 0.068226 0.046524 1.466 0.143
L1.Wien -0.100849 0.090381 -1.116 0.264
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162068 0.101370 1.599 0.110
L1.Burgenland -0.005530 0.052326 -0.106 0.916
L1.Kärnten 0.062408 0.025377 2.459 0.014
L1.Niederösterreich 0.194369 0.110936 1.752 0.080
L1.Oberösterreich -0.128875 0.109686 -1.175 0.240
L1.Salzburg 0.246578 0.053801 4.583 0.000
L1.Steiermark 0.157987 0.071313 2.215 0.027
L1.Tirol 0.052216 0.056323 0.927 0.354
L1.Vorarlberg 0.121805 0.050723 2.401 0.016
L1.Wien 0.140149 0.098539 1.422 0.155
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.513859 0.054844 9.370 0.000
L1.Burgenland -0.023322 0.028310 -0.824 0.410
L1.Kärnten -0.009016 0.013729 -0.657 0.511
L1.Niederösterreich 0.191315 0.060019 3.188 0.001
L1.Oberösterreich 0.259561 0.059343 4.374 0.000
L1.Salzburg 0.022304 0.029108 0.766 0.444
L1.Steiermark -0.027415 0.038582 -0.711 0.477
L1.Tirol 0.071349 0.030472 2.341 0.019
L1.Vorarlberg 0.058779 0.027442 2.142 0.032
L1.Wien -0.055412 0.053312 -1.039 0.299
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.019558 0.066243 0.135921 0.120454 0.035384 0.065545 -0.004206 0.180757
Kärnten 0.019558 1.000000 -0.055260 0.129573 0.045517 0.069658 0.458995 -0.093089 0.101032
Niederösterreich 0.066243 -0.055260 1.000000 0.290905 0.090568 0.274574 0.013181 0.147721 0.255398
Oberösterreich 0.135921 0.129573 0.290905 1.000000 0.176382 0.295782 0.163558 0.119044 0.135858
Salzburg 0.120454 0.045517 0.090568 0.176382 1.000000 0.124918 0.049593 0.108179 0.050605
Steiermark 0.035384 0.069658 0.274574 0.295782 0.124918 1.000000 0.129293 0.087230 -0.025217
Tirol 0.065545 0.458995 0.013181 0.163558 0.049593 0.129293 1.000000 0.035965 0.127179
Vorarlberg -0.004206 -0.093089 0.147721 0.119044 0.108179 0.087230 0.035965 1.000000 -0.047894
Wien 0.180757 0.101032 0.255398 0.135858 0.050605 -0.025217 0.127179 -0.047894 1.000000